// import { isArray } from '@/utils'

const platform = {
  state: {
    huobi: {
      market_depth: {iosteth: [], iostbtc: [], htbtc: []},
      symbols: ['iosteth', 'iostbtc', 'htbtc', 'hteth']
    },
    okex: {market_depth: []},
    cnTrading: ['卖5', '卖4', '卖3', '卖2', '卖1', '买1', '买2', '买3', '买4', '买5'],
    symbols: [],
    conf: {
      cc: 1
    }
  },
  mutations: {
    // 初始化交易数据
    INIT_PLATFORM: (state, arg) => {
      let platforms = ['huobi', 'okex']
      platforms.forEach(function (platform) {
        Object.keys(state[platform].market_depth).forEach(function (iv) {
          state[platform].market_depth[iv] = {from: '-', to: '-', list: [['-', '-'], ['-', '-'], ['-', '-'], ['-', '-'], ['-', '-'], ['-', '-'], ['-', '-'], ['-', '-'], ['-', '-'], ['-', '-']]}
        })
      })
      // console.log(state)
    },
    // 设置数据深度
    SET_MARKET_DEPTH: (state, arg) => {
      // 以下函数才会触发视图更新 push() pop() shift() unshift() splice() sort() reverse()
      state[arg.platform]['market_depth'][arg.symbol] = {from: arg.from, to: arg.to, list: arg.market_depth}
      // console.log(state)
    },
    SET_CONF: (state, arg) => {
      state.conf[arg.key] = arg.value
      console.log(state.conf)
    }
  },
  actions: {
    // 初始化交易对数据
    InitPlatform ({ commit }) {
      commit('INIT_PLATFORM')
    },
    SetMarketDepth ({ commit }, arg) {
      commit('SET_MARKET_DEPTH', arg)
    },
    SetConf ({ commit }, arg) {
      commit('SET_CONF', arg)
    }
  }
}

export default platform
